function SlideUpDown(element) {
	var e = $('#' + element);
	if (e.css('display') == 'none') {
		e.show().find('div').slideDown('slow')
	} else {
		 e.find('div').slideUp('slow', function() { $(this).parent().parent().hide(); })
	}
}

function enableInputs(enable, parentElem){
    var parId = typeof parentElem == "undefined" ? "content" : parentElem;
    var cont = document.getElementById(parId);
    var inputs=cont.getElementsByTagName("input");
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            if(inputs[i].type == "hidden" || inputs[i].class== "hidden")
                continue;
            if(inputs[i].type == "text" || inputs[i].type=="checkbox" || (inputs[i].type == "submit" && inputs[i].classList.contains("save")) )
                inputs[i].disabled = !enable;
        }
    }
    inputs=cont.getElementsByTagName("select");
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            if(inputs[i].name == "style" || inputs[i].class== "hidden")
                continue;
            inputs[i].disabled = !enable;
        }
    }
    
}

function toogleInputs(parentElem){
    var parId = typeof parentElem == "undefined" ? "content" : parentElem;
    var cont = document.getElementById(parId);
    
    var inputs=cont.getElementsByTagName("input");
    
    var disabled=true;
    var set = false;
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            if(inputs[i].type == "hidden" || inputs[i].class== "hidden")
                continue;
            if(inputs[i].type == "text" || inputs[i].type=="checkbox"){
                disabled = inputs[i].disabled;
                set = true;
                break;
            }
        }
    }
    if(!set){
        inputs=cont.getElementsByTagName("select");
        if(inputs!=null && inputs.length>0){
            for(i=0;i<inputs.length;i++){
                if(inputs[i].name == "style" || inputs[i].class== "hidden")
                    continue;
                disabled = inputs[i].disabled;
                break;
            }
        }
    }
    if(disabled){
        enableInputs(true, parentElem);
    }
    else if(checkModified(parentElem)){
        var res = confirm (MSG_CONFIRM_DISCARD_CHANGES);
        if(res) {
            restoreDefault(parentElem);
            enableInputs(false, parentElem);
        }
    } else 
        enableInputs(false,parentElem);
}

function restoreDefault(parentElem){
    var parId = typeof parentElem == "undefined" ? "content" : parentElem;
    var cont = document.getElementById(parId);
    var inputs=cont.getElementsByTagName("input");
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            if(inputs[i].type == "hidden" || inputs[i].class== "hidden")
                continue;
            if(inputs[i].type == "text" || inputs[i].type=="checkbox" || inputs[i].type=="select"){
                var hidden=document.getElementById("h"+inputs[i].id);
                if(hidden!=null){
                    if(inputs[i].type == "text"){
                        inputs[i].value=hidden.value;
                    } else if(inputs[i].type=="checkbox"){
                        inputs[i].checked=hidden.checked;
                    } 
                }
            }
        }
    }
    inputs=cont.getElementsByTagName("select");
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            var hidden=document.getElementById("h"+inputs[i].id);
            if(hidden!=null){
                for(j=0;j<inputs[i].options.length;j++){
                    if(inputs[i].options[j].value==hidden.value){
                        inputs[i].options[j].selected = true;
                    } else {
                        inputs[i].options[j].selected = false;
                    }
                } 
            }
        }
    }
}

function checkModified(parentElem){
    var parId = typeof parentElem == "undefined" ? "content" : parentElem;
    var cont = document.getElementById(parId);
    var inputs=cont.getElementsByTagName("input");
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            if(inputs[i].type == "hidden" || inputs[i].class== "hidden")
                continue;
            if(inputs[i].type == "text" || inputs[i].type=="checkbox"){
                var hidden=document.getElementById("h"+inputs[i].id);
                if(hidden!=null){
                    if(inputs[i].type == "text"){
                        if(inputs[i].value!=hidden.value)
                            return true;
                    } else if(inputs[i].type=="checkbox"){
                        if(inputs[i].checked!=hidden.checked)
                            return true;
                    } 
                }
            }
        }
    }
    inputs=cont.getElementsByTagName("select");
    if(inputs!=null && inputs.length>0){
        for(i=0;i<inputs.length;i++){
            var hidden=document.getElementById("h"+inputs[i].id);
            if(hidden!=null){
                for(j=0;j<inputs[i].options.length;j++){
                    if(inputs[i].options[j].value==hidden.value){
                        if(!inputs[i].options[j].selected)
                            return true;
                    }
                } 
            }
        }
    }
    return false;
}

function numOnlyInput(event){
    var charCode = (event.which) ? event.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
     return true;
}

function confirmDelete(){
    var res = confirm(MSG_CONFIRM_DELETE);
    return res;
}